extension ListExtension<T> on List<T> {
  static List<T>? createList<T>(dynamic value, T Function(dynamic) decode) {
    if (value == null) {
      return null;
    }

    if (value is List) {
      return value.map<T>((e) => decode(e)).toList();
    }

    return null;
  }

  int? indexOrNull(T element) {
    final index = indexWhere((e) => e == element);
    return index == -1 ? null : index;
  }

  int? indexWhereOrNull(bool Function(T element) test, [int start = 0]) {
    final index = indexWhere(test, start);
    return index == -1 ? null : index;
  }

  T? firstWhereOrNull(bool Function(T element) test, [int start = 0]) {
    final index = indexWhere(test);
    return index == -1 ? null : this[index];
  }
}
